<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教师管理系统 - 登录</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.13/theme-chalk/index.css" rel="stylesheet">
    <style>
        .login-container {
            width: 100%;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f5f7fa;
        }
        .login-box {
            width: 400px;
            padding: 30px;
            background-color: #fff;
            border-radius: 4px;
            box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
        }
        .login-title {
            text-align: center;
            margin-bottom: 30px;
            font-size: 24px;
            color: #303133;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="login-container">
            <div class="login-box">
                <h2 class="login-title">教师管理系统</h2>
                <el-form :model="loginForm" :rules="rules" ref="loginForm">
                    <el-form-item prop="employeeNumber">
                        <el-input v-model="loginForm.employeeNumber" placeholder="请输入学工号">
                            <template slot="prepend">
                                <i class="el-icon-user"></i>
                            </template>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input v-model="loginForm.password" type="password" placeholder="请输入密码">
                            <template slot="prepend">
                                <i class="el-icon-lock"></i>
                            </template>
                        </el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" style="width: 100%" @click="handleLogin" :loading="loading">
                            登录
                        </el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.13/index.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.4/axios.min.js"></script>
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    loginForm: {
                        employeeNumber: '',
                        password: ''
                    },
                    rules: {
                        employeeNumber: [
                            { required: true, message: '请输入学工号', trigger: 'blur' }
                        ],
                        password: [
                            { required: true, message: '请输入密码', trigger: 'blur' }
                        ]
                    },
                    loading: false
                }
            },
            methods: {
                handleLogin() {
                    this.$refs.loginForm.validate(valid => {
                        if (valid) {
                            this.loading = true;
                            axios.post('/api/login', this.loginForm)
                                .then(response => {
                                    if (response.data.code === 1) {
                                        localStorage.setItem('token', response.data.data.token);
                                        this.$message.success('登录成功');
                                        window.location.href = '/index.html';
                                    } else {
                                        this.$message.error(response.data.msg || '登录失败');
                                    }
                                })
                                .catch(error => {
                                    this.$message.error(error.response?.data?.msg || '系统错误');
                                })
                                .finally(() => {
                                    this.loading = false;
                                });
                        }
                    });
                }
            }
        });
    </script>
</body>
</html>
